﻿<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<link rel="stylesheet" type="text/css" href="stylesheets/user.css" />
<link rel="stylesheet" type="text/css" href="stylesheets/index.css" />
<title>用户组添加</title>
</head>
<body>
    <div class="sys_contnt">
        <div class="sys_content_left">
            <ul>
                <li ><a href="/group_list" id="groupmanager">用户组管理</a></li>
                <li class="sys_content_left_l1"><a id="grouplist" href="/group_add">用户组添加</a></li>
            </ul>
        </div>
        <div class="sys_content_right" >
            <h1>用户组添加</h1>
            <form action="" method="post" id="add_gro_form">
                <div class="con">
                    <span class="title">组名称：</span>
                    <input class="text" id="groupname" type="text" />
                    <div class="user_content">
                        <span class="title">组权限：</span>
                        <div class="rep_box">
                            <span>
                                <input id="allgroup" type="checkbox" value="" name="allgroup" title="100"/>全选</span>
                            <div class="rep_box_bottom">
                                <div class="list">
                                    <h3>
                                        <input type="checkbox"  name="group1" id="group1" title="1001"/>文章管理</h3>
                                    <ul  class="group1-select">
                                        <li>
                                            <input type="checkbox"  title="10011"/>添加文章</li>
                                        <li>
                                            <input type="checkbox" title="10012"/>删除文章</li>
                                        <li>
                                            <input type="checkbox" title="10013"/>修改文章</li>

                                        </ul>
                                </div>
                                <div class="list">
                                    <h3>
                                        <input type="checkbox"  name="group2" id="group2"  title="1002"/>用户管理</h3>
                                    <ul class="group2-select">
                                        <li>
                                            <input type="checkbox" title="10021"/>添加用户</li>
                                        <li>
                                            <input type="checkbox" title="10022"/>删除用户</li>
                                        <li>
                                            <input type="checkbox" title="10023"/>修改用户</li>
                                    </ul>
                                </div>
                            </div>
                        </div>
                    </div>
                    <input type="submit" class="btn_sub btn_sub_center" value="提 交"  id="commitgroupinfor"/>
                </div>
            </form>
        </div>
    </div>
</body>
<script src="/javascripts/jquery-3.2.1.min.js"></script>
<script src="/routes/group.js"></script>
<script src="/javascripts/jQuery.js"></script>
<script>
    $(function () {
        $('#allgroup').on('click', function () {
            boxs = $('.rep_box [type = "checkbox"]');
            if ($(this).is(':checked')) {
                $(boxs).prop({'checked': true});
            } else {
                $(boxs).prop({'checked': false});
            }
        });
        $('#group1').on('click', function () {
            boxs = $('.group1-select [type = "checkbox"]');
            if ($(this).is(':checked')) {
                $(boxs).prop({'checked': true});
            } else {
                $(boxs).prop({'checked': false});
            }
        });
        $('#group2').on('click', function () {
            boxs = $('.group2-select [type = "checkbox"]');
            if ($(this).is(':checked')) {
                $(boxs).prop({'checked': true});
            } else {
                $(boxs).prop({'checked': false});
            }
        });

        $('#add_gro_form').on('submit', function () {
            boxs1 = $('.group1-select [type = "checkbox"]:checked');
            boxs2 = $('.group2-select [type = "checkbox"]:checked');
            var data_send = [];
            boxs1.each(function () {
                data_send.push($(this).attr('title'));
            });
            boxs2.each(function () {
                data_send.push($(this).attr('title'));
            });
            //var groupname = $('#groupname').val();
            var data = {
                data_send: data_send.toString(),
                groupname: $('#groupname').val()
            };
            console.log(data);
            $.ajax({
                url: "/addgroup",
                data: data,
                type: "post",
                success: function (data) {
                    alert(data);
                    window.history.go(0);
                },
                error: function (err) {
                    console.log(err);
                }
            });
        });
    });
</script>
</html>
